import pickle



def get_device_user_dict(user_str):

    # 从文件中读取并反序列化对象
    with open('device_message_list.pkl', 'rb') as file:
        loaded_data = pickle.load(file)


    # print("对象已从 data.pkl 反序列化")
    # print(loaded_data)
    device_message_list = loaded_data
    device_user_dict = {}
    # 遍历字典并打印键和值
    for key1, value1 in device_message_list.items():

        for key2, value2 in value1.items():
            # print(f"键: {key}, 值: {value}")
            if user_str in key2:
                # print(66)
                # print(key2)
                device_user_dict.update({key1:key2})
    # print(device_user_dict)

    return device_user_dict


if __name__ == "__main__":
    device_user_dict = get_device_user_dict("欢")
    print(device_user_dict)

